package com.dstz.bpm.act.listener;

import com.dstz.base.core.util.AppUtil;
import java.util.HashMap;
import java.util.Map;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.delegate.event.impl.ActivitiEventImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GlobalEventListener implements ActivitiEventListener {
   private final Logger logger = LoggerFactory.getLogger(this.getClass());
   private Map<String, String> g = new HashMap();

   public void onEvent(ActivitiEvent event) {
      String eventType = event.getType().name();
      String eventHandlerBeanId = (String)this.g.get(eventType);
      if (eventHandlerBeanId != null) {
         ActEventListener handler = (ActEventListener)AppUtil.getBean(eventHandlerBeanId);
         ActivitiEventImpl e = (ActivitiEventImpl)event;
         handler.notify(e);
      } else {
         this.logger.debug("eventListener:{} skiped" + eventType);
      }

   }

   public boolean isFailOnException() {
      return true;
   }

   public Map<String, String> getHandlers() {
      return this.g;
   }

   public void setHandlers(Map<String, String> handlers) {
      this.g = handlers;
   }
}
